package com.springleaf.arena.display
{
	import com.springleaf.arena.state.CreatureState;
	import com.springleaf.common.display.UISprite;

	public class UICreature extends UIDisplayableObject
	{
		private var currentAnimation:Array;
		private var currentFrame:int = -1;
		private var animationFunction:Function;
		
		private var _currentState:int;
		private var _idleStateSouth:Array;
		
		public function UICreature() {
		}
		
		public function updateAnimation():void {
			animationFunction();
		}
		
		private function loadAnimation():void {
			switch (_currentState) {
				case CreatureState.IDLE_STATE_SOUTH :
					currentAnimation = idleStateSouth;
					break;
				default :
					break;
			}
			loadAnimationFunction();
		}
		
		private function loadAnimationFunction():void {
			if (currentAnimation.length > 1) {
				animationFunction = drawNextFrame;
			} else {
				animationFunction = doNothing;
			}
		}
		
		private function drawNextFrame():void {
			if (++currentFrame < currentAnimation.length) {
				render(currentAnimation[currentFrame].rectangle, currentAnimation[currentFrame].point);
			} else {
				currentFrame = 0;
				render(currentAnimation[currentFrame].rectangle, currentAnimation[currentFrame].point);
			}
		}
		
		private function doNothing():void {}
		
		public function set idleStateSouth(state:Array):void {
			_idleStateSouth = state;
		}
		
		public function get idleStateSouth():Array {
			return _idleStateSouth;
		}

		public function get currentState():int
		{
			return _currentState;
		}

		public function set currentState(value:int):void
		{
			_currentState = value;
			loadAnimation();
		}

	}
}